﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IChecksumGenerator</summary>
    public class IChecksumGenerator : IDisposable
    {
        public string ID; // ID generatora

        /// <summary>Konstruktor</summary>
        public IChecksumGenerator()
        {
        }
        /// <summary>Dispose metoda</summary>
        public virtual void Dispose()
        {
        }

        /// <summary>Inicializacia</summary>
        public virtual void Init()
        {
        }
        /// <summary>Uzatvorenie generatora</summary>
        public virtual void Finish()
        {
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public virtual void AddData(int pLength, IntPtr pData)
        {
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public virtual void AddData(int pLength, byte[] pData)
        {
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public virtual string HEX_VALUE
        {
            get
            {
                return "";
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public virtual string GenerateFileContent(string pFileName)
        {
            return "";
        }

        /// <summary>Vytvorenie generatora podla ID</summary>
        /// <param name="pID">ID</param>
        /// <returns>objekt generatora</returns>
        public static IChecksumGenerator CreateGenerator(string pID)
        {
            switch (pID)
            {
                case "CRC32": return new ICRCChecksumGenerator();
                case "MD5": return new IMD5ChecksumGenerator();
                case "SHA1": return new ISHA1ChecksumGenerator();
                case "SHA256": return new ISHA256ChecksumGenerator();
                case "SHA384": return new ISHA384ChecksumGenerator();
                case "SHA512": return new ISHA512ChecksumGenerator();
                default: return null;
            }
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class ICRCChecksumGenerator : IChecksumGenerator
    {
        protected ICRC32 FCRC;

        /// <summary>Konstruktor</summary>
        public ICRCChecksumGenerator()
        {
            ID = "CRC32";
            FCRC = new ICRC32();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            FCRC = (ICRC32)ICore.DisposeObject(FCRC);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            FCRC.Init();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            FCRC.Finish();
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            FCRC.AddDataBlock(pData, 0, pLength);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            FCRC.AddDataBlock(pData, 0, pLength);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                return FCRC.HEXValue;
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return "; " + lang.FILE_EXPLORER_TEXT_28_4 + Environment.NewLine + pFileName + " " + HEX_VALUE.ToLower();
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class IMD5ChecksumGenerator : IChecksumGenerator
    {
        protected System.Security.Cryptography.MD5 md5;
        protected byte[] FBuffer = null;

        /// <summary>Konstruktor</summary>
        public IMD5ChecksumGenerator()
        {
            ID = "MD5";
            md5 = System.Security.Cryptography.MD5.Create();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            md5 = (System.Security.Cryptography.MD5)ICore.DisposeObject(md5);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            md5.Initialize();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            md5.TransformFinalBlock(new byte[0], 0, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            if ((FBuffer == null) || (FBuffer.Length < pLength)) FBuffer = new byte[pLength]; // Alokujem bufer
            for (int i = 0; i < pLength; i++) FBuffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(pData, i);
            md5.TransformBlock(FBuffer, 0, pLength, FBuffer, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            md5.TransformBlock(pData, 0, pLength, pData, 0);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                byte[] Result = md5.Hash; // Vysledok
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder
                foreach (byte B1 in Result)
                {
                    B.Append(B1.ToString("X2"));
                }
                return B.ToString(); 
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return HEX_VALUE.ToLower() + " *" + pFileName;
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class ISHA1ChecksumGenerator : IChecksumGenerator
    {
        protected System.Security.Cryptography.SHA1 sha;
        protected byte[] FBuffer = null;

        /// <summary>Konstruktor</summary>
        public ISHA1ChecksumGenerator()
        {
            ID = "SHA1";
            sha = System.Security.Cryptography.SHA1.Create();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            sha = (System.Security.Cryptography.SHA1)ICore.DisposeObject(sha);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            sha.Initialize();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            sha.TransformFinalBlock(new byte[0], 0, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            if ((FBuffer == null) || (FBuffer.Length < pLength)) FBuffer = new byte[pLength]; // Alokujem bufer
            for (int i = 0; i < pLength; i++) FBuffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(pData, i);
            sha.TransformBlock(FBuffer, 0, pLength, FBuffer, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            sha.TransformBlock(pData, 0, pLength, pData, 0);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                byte[] Result = sha.Hash; // Vysledok
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder
                foreach (byte B1 in Result)
                {
                    B.Append(B1.ToString("X2"));
                }
                return B.ToString();
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return HEX_VALUE.ToLower() + " *" + pFileName;
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class ISHA256ChecksumGenerator : IChecksumGenerator
    {
        protected System.Security.Cryptography.SHA256 sha;
        protected byte[] FBuffer = null;

        /// <summary>Konstruktor</summary>
        public ISHA256ChecksumGenerator()
        {
            ID = "SHA256";
            sha = System.Security.Cryptography.SHA256.Create();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            sha = (System.Security.Cryptography.SHA256)ICore.DisposeObject(sha);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            sha.Initialize();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            sha.TransformFinalBlock(new byte[0], 0, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            if ((FBuffer == null) || (FBuffer.Length < pLength)) FBuffer = new byte[pLength]; // Alokujem bufer
            for (int i = 0; i < pLength; i++) FBuffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(pData, i);
            sha.TransformBlock(FBuffer, 0, pLength, FBuffer, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            sha.TransformBlock(pData, 0, pLength, pData, 0);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                byte[] Result = sha.Hash; // Vysledok
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder
                foreach (byte B1 in Result)
                {
                    B.Append(B1.ToString("X2"));
                }
                return B.ToString();
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return HEX_VALUE.ToLower() + " *" + pFileName;
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class ISHA384ChecksumGenerator : IChecksumGenerator
    {
        protected System.Security.Cryptography.SHA384 sha;
        protected byte[] FBuffer = null;

        /// <summary>Konstruktor</summary>
        public ISHA384ChecksumGenerator()
        {
            ID = "SHA384";
            sha = System.Security.Cryptography.SHA384.Create();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            sha = (System.Security.Cryptography.SHA384)ICore.DisposeObject(sha);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            sha.Initialize();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            sha.TransformFinalBlock(new byte[0], 0, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            if ((FBuffer == null) || (FBuffer.Length < pLength)) FBuffer = new byte[pLength]; // Alokujem bufer
            for (int i = 0; i < pLength; i++) FBuffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(pData, i);
            sha.TransformBlock(FBuffer, 0, pLength, FBuffer, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            sha.TransformBlock(pData, 0, pLength, pData, 0);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                byte[] Result = sha.Hash; // Vysledok
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder
                foreach (byte B1 in Result)
                {
                    B.Append(B1.ToString("X2"));
                }
                return B.ToString();
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return HEX_VALUE.ToLower() + " *" + pFileName;
        }
    }

    /// <summary>Trieda IChecksumGenerator</summary>
    public class ISHA512ChecksumGenerator : IChecksumGenerator
    {
        protected System.Security.Cryptography.SHA512 sha;
        protected byte[] FBuffer = null;

        /// <summary>Konstruktor</summary>
        public ISHA512ChecksumGenerator()
        {
            ID = "SHA512";
            sha = System.Security.Cryptography.SHA512.Create();
        }
        /// <summary>Dispose metoda</summary>
        public override void Dispose()
        {
            sha = (System.Security.Cryptography.SHA512)ICore.DisposeObject(sha);
        }

        /// <summary>Inicializacia</summary>
        public override void Init()
        {
            sha.Initialize();
        }
        /// <summary>Uzatvorenie generatora</summary>
        public override void Finish()
        {
            sha.TransformFinalBlock(new byte[0], 0, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, IntPtr pData)
        {
            if ((FBuffer == null) || (FBuffer.Length < pLength)) FBuffer = new byte[pLength]; // Alokujem bufer
            for (int i = 0; i < pLength; i++) FBuffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(pData, i);
            sha.TransformBlock(FBuffer, 0, pLength, FBuffer, 0);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">buffer</param>
        public override void AddData(int pLength, byte[] pData)
        {
            sha.TransformBlock(pData, 0, pLength, pData, 0);
        }

        /// <summary>Vysledok ako HEX hodnota</summary>
        public override string HEX_VALUE
        {
            get
            {
                byte[] Result = sha.Hash; // Vysledok
                System.Text.StringBuilder B = new System.Text.StringBuilder(); // Builder
                foreach (byte B1 in Result)
                {
                    B.Append(B1.ToString("X2"));
                }
                return B.ToString();
            }
        }
        /// <summary>Generovanie obsahu suboru s kontrolnym suctom</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>obsah</returns>
        public override string GenerateFileContent(string pFileName)
        {
            return HEX_VALUE.ToLower() + " *" + pFileName;
        }
    }

    /// <summary>Trieda IGenerateChecksumDataStruct</summary>
    public class IGenerateChecksumDataStruct : IDisposable
    {
        public string DestinationPath; // Cielova cesta
        public System.Collections.Generic.List<string> SourceFiles; // Zdrojove subory
        public string UsedChecksumTypes; // Zoznam pouzitych typov kontrolnych suctov
        public System.Collections.Generic.List<IChecksumGenerator> Generators; // Zoznam objektov generatorov
        public bool UseOwnFiles; // Priznak pouzitia samostatnych suborov
        public string CommonFileName; // Vseobecne meno vystupneho suboru

        /// <summary>Konstruktor</summary>
        public IGenerateChecksumDataStruct()
        {
            SourceFiles = new System.Collections.Generic.List<string>();
            Generators = new System.Collections.Generic.List<IChecksumGenerator>();
        }
        /// <summary>Dispose metoda</summary>
        public void Dispose()
        {
            if (Generators != null)
            {
                for (int i = 0; i < Generators.Count; i++) Generators[i].Dispose();
                SourceFiles.Clear();

                Generators = null; SourceFiles = null;
            }
        }

        /// <summary>Zmena nastavenia generovania pomocou formulara</summary>
        public bool EditWithForm()
        {
            using (IFileExplorerForm_GenerateChecksum F = new IFileExplorerForm_GenerateChecksum())
            {
                F.Value = this;
                return F.ShowDialog() == System.Windows.Forms.DialogResult.OK;
            }
        }

        /// <summary>Inicializacia generatorov</summary>
        public void CreateGenerators()
        {
            string[] S = UsedChecksumTypes.Split(new char[] { ';' });
            foreach (string ID in S) // Vytvorim pole generatorov
            {
                Generators.Add(IChecksumGenerator.CreateGenerator(ID));
            }
        }
        /// <summary>Inicializacia generatorov</summary>
        public void InitGenerators()
        {
            foreach (IChecksumGenerator G in Generators) G.Init(); // Inicializujem kazdy z nich
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">data</param>
        public void AddData(int pLength, IntPtr pData)
        {
            foreach (IChecksumGenerator G in Generators) G.AddData(pLength, pData);
        }
        /// <summary>Zaradenie dat do vypoctu</summary>
        /// <param name="pLength">dlzka</param>
        /// <param name="pData">data</param>
        public void AddData(int pLength, byte[] pData)
        {
            foreach (IChecksumGenerator G in Generators) G.AddData(pLength, pData);
        }
        /// <summary>Uzatvorenie pocitania generatorov</summary>
        public void Finish()
        {
            foreach (IChecksumGenerator G in Generators) G.Finish();
        }

        /// <summary>Ziskanie zoznamu ID podporovanych typov kontrolnych suctov</summary>
        /// <returns></returns>
        public static System.Collections.Generic.List<string> GetSupportedChecksumIDs()
        {
            System.Collections.Generic.List<string> Result = new System.Collections.Generic.List<string>();
            Result.Add("CRC32");
            Result.Add("MD5");
            Result.Add("SHA1");
            Result.Add("SHA256");
            Result.Add("SHA384");
            Result.Add("SHA512");
            return Result;
        }
        /// <summary>Prevod ID typu kontrolneho suctu na popis</summary>
        /// <param name="pID">ID</param>
        /// <returns>popis</returns>
        public static string ID2String(string pID)
        {
            switch (pID)
            {
                case "CRC32": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_1;
                case "MD5": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_2;
                case "SHA1": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_3;
                case "SHA256": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_4;
                case "SHA384": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_5;
                case "SHA512": return lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_8_6;
                default: return "";
            }
        }
        /// <summary>Ziskanie pripony pre dany typ kontr. suctu</summary>
        /// <param name="pID">ID</param>
        /// <returns>pripona</returns>
        public static string GetExtension(string pID)
        {
            switch (pID)
            {
                case "CRC32": return "sfv";
                case "MD5": return "md5";
                case "SHA1": return "sha";
                case "SHA256": return "sha256";
                case "SHA384": return "sha384";
                case "SHA512": return "sha512";
                default: return "";
            }
        }
    }

    /// <summary>Trieda IFileExplorerForm_GenerateChecksum</summary>
    public class IFileExplorerForm_GenerateChecksum : IForm
    {
        public IGenerateChecksumDataStruct Value; // Editovany objekt

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_OK;
        protected IButton FBtn_Cancel;

        protected ILabel FLabel1;
        protected ITextBox FText_Destination;
        protected IButton FBtn_ChooseDestination;
        protected ICheckBox FCheck_MultiFiles;
        protected ILabel FLabel2;
        protected ICheckedListBox FList_ChecksumTypes;

        /// <summary>Konstruktor</summary>
        public IFileExplorerForm_GenerateChecksum()
        {
        }

        /// <summary>Metoda: OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            // Inicializacia
            MinimizeBox = false; MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowIcon = true; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            SetBounds(0, 0, 400, 340); System.Drawing.Size CS = ClientSize;
            Text = lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_1;

            // Vytvorim groupbox
            FGrp = new IGroupBox(); IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50);
            System.Drawing.Size CS1 = FGrp.ClientSize;

            FLabel1 = new ILabel(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_4);
            FText_Destination = new ITextBox(); FText_Destination.ReadOnly = true;
            FBtn_ChooseDestination = new IButton(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_5, Event_BtnChooseClick, false);
            FCheck_MultiFiles = new ICheckBox(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_6); FCheck_MultiFiles.Enabled = Value.SourceFiles.Count > 1;
            FLabel2 = new ILabel(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_7);
            FList_ChecksumTypes = new ICheckedListBox();
            
            System.Collections.Generic.List<string> L = IGenerateChecksumDataStruct.GetSupportedChecksumIDs();
            foreach (string S in L) FList_ChecksumTypes.AddItem(string.Format(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_9, IGenerateChecksumDataStruct.ID2String(S), IGenerateChecksumDataStruct.GetExtension(S)), S);

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel1, FText_Destination, FBtn_ChooseDestination, FCheck_MultiFiles, FLabel2, FList_ChecksumTypes });

            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel1, FGrp, 10, 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_Destination, FLabel1, 1, 6, CS1.Width - 99);
            IControl.PlaceControl_Outside_LeftTop_TopRight(FBtn_ChooseDestination, FText_Destination, -1, 10, 70, FText_Destination.Height + 2);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FCheck_MultiFiles, FText_Destination, 0, 10);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FLabel2, FCheck_MultiFiles, 0, 16);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FList_ChecksumTypes, FLabel2, 0, 8, CS1.Width - 20, CS1.Height - FLabel2.Bottom - 16);

            // Vytvorim tlacidla
            FBtn_Cancel = new IButton(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_3); IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10); FBtn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            FBtn_OK = new IButton(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_2, Event_BtnOKClick); IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_OK, FBtn_Cancel }); // Zaradim do controls

            FText_Destination.Text = Value.DestinationPath; // Vyplnim cielovu cestu

            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus();
            return true; // Vsetko OK
        }

        /// <summary>Event: Click pre tlacidlo OK</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnOKClick(object pSender, EventArgs e)
        {
            string IDs = FList_ChecksumTypes.AllCheckedItemIDs;
            if (IDs == "") // Ziaden typ nebol vybrany?
            {
                IApp.ShowError(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_11);
                FList_ChecksumTypes.Focus();
                return;
            }

            Value.DestinationPath = FText_Destination.Text; // Ulozim do vysledku
            Value.UsedChecksumTypes = IDs;
            Value.UseOwnFiles = Value.SourceFiles.Count == 1 ? true : FCheck_MultiFiles.Checked;
            Value.CommonFileName = "checksums";
            
            DialogResult = System.Windows.Forms.DialogResult.OK; // OK
        }
        /// <summary>Event: Click pre tlacidlo 'Vybrat'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnChooseClick(object pSender, EventArgs e)
        {
            string P = IApp.ShowEditor_ChooseDirectory(lang.FORM_EDIT_GENERATE_CHECKSUM_TEXT_10, FText_Destination.Text); // Volam vyber cesty
            if (P != "") FText_Destination.Text = P; // Ak som vybral nahradim aktualnu
        }
    }
}
